package com.example.shortmessage.tips.dialog;


import android.content.Context;
import android.content.DialogInterface;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.example.shortmessage.R;
import com.example.shortmessage.data.constant.DialogConst;
import com.example.shortmessage.interfaces.DialogOnClickInterface;

/**
 * 两个选择的对话框
 * @author 27638
 */
public class NormalDialog {
    private static NormalDialog instance;
    private static Context context;
    private static DialogOnClickInterface dialogOnClickInterface;

    public static NormalDialog getInstance(@NonNull Context context, @NonNull DialogOnClickInterface dialogOnClickInterface) {
        if (instance == null) {
            instance = new NormalDialog();
            NormalDialog.context = context;
            NormalDialog.dialogOnClickInterface = dialogOnClickInterface;
        }
        return instance;
    }
    public void createDialog(String title, String message, String positive){
        final AlertDialog.Builder normalDialog = new AlertDialog.Builder(context);
        normalDialog.setIcon(R.mipmap.ic_logo);
        normalDialog.setTitle(title);
        normalDialog.setMessage("\n"+message+"\n");
        normalDialog.setCancelable(false);
        normalDialog.setPositiveButton(positive,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogOnClickInterface.interfacePositive();
                        dialog.dismiss();
                    }
                });
        normalDialog.setNegativeButton(DialogConst.positive,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialogOnClickInterface.interfaceNegative();
                        dialog.dismiss();
                    }
                });
        normalDialog.show();
    }
}
